How to Set the PATH Variable on Windows, macOS, and Linux

This guide shows how to set the PATH environment variable on each OS, including temporary (current terminal only) and permanent methods.

Windows

Permanent (GUI – Recommended)

  1. Open the Start Menu and search for Environment Variables.
  2. Click Edit the system environment variables.
  3. Click Environment Variables….
  4. Under User variables (preferred) or System variables:
  5. Click OK on all dialogs.
  6. Restart terminals (important).

User Path affects only your account. System Path affects all users and typically requires administrator privileges.

Temporary (Current Terminal Only)

Command Prompt (cmd.exe):

set PATH=C:\MyApp\bin;%PATH%

PowerShell:

$env:PATH = "C:\MyApp\bin;$env:PATH"

macOS

Permanent (Recommended – zsh default)

Edit your zsh config:

nano ~/.zshrc

Add this line:

export PATH="/usr/local/myapp/bin:$PATH"

Apply immediately:

source ~/.zshrc

GUI apps sometimes don’t read shell config files. If a GUI app can’t find your command, you may need to set PATH using launchctl and log out/in afterward:

launchctl setenv PATH "/usr/local/myapp/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Temporary

export PATH="/usr/local/myapp/bin:$PATH"

Linux

Permanent (User-Level – Recommended)

Edit one of these files (depending on your shell/distro):

~/.bashrc
~/.bash_profile
~/.profile
~/.zshrc

Add:

export PATH="$HOME/myapp/bin:$PATH"

Apply:

source ~/.bashrc

Permanent (System-Wide)

Edit one of these (requires sudo):

sudo nano /etc/profile

or

sudo nano /etc/environment

Example (in /etc/environment):

PATH="/usr/local/myapp/bin:/usr/bin:/bin"

System-wide changes often require a logout/login (or reboot) to fully apply.

Temporary

export PATH="$HOME/myapp/bin:$PATH"

Verify Your PATH

macOS / Linux:

echo $PATH
which mycommand

Windows:

where mycommand

Common Mistakes

Best Practice Summary

OS Best Permanent Method Temporary Method
Windows User Environment Variables (Path) set PATH=...;%PATH% or $env:PATH=...
macOS ~/.zshrc export PATH="...:$PATH"
Linux ~/.bashrc or ~/.profile export PATH="...:$PATH"